package com.symc.sims0213xfw.dao.impl;

import com.symc.sims0213xfw.dao.StudentDao;
import com.symc.sims0213xfw.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
 * @Author: 凤文  沈阳医学院2019级医学信息工程 0213
 * @CreateTime: 2022/01/22 20:05
 * @Description:
 */
public class StudentDaoImpl implements StudentDao {
    private static QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());

    @Override
    public int addStudent(String id, String name, String classId, Integer isVisible) {
        String sql = "insert into student value(?,?,?,?)";
        int i = 0;
        try {
            i = qr.update(sql, new Object[]{id, name, classId, isVisible});
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return i;
    }

    @Override
    public int updateStudent(String id,String name,String classId,
                             Integer isVisible) {
        String sql = "update student set name=?,cid=?,isVisible=? where id=?";
        int i = 0;
        try {
            i = qr.update(sql,new Object[]{name,classId,isVisible,id});
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return i;
    }

    @Override
    public int setStudentIsVisible(String id, Integer isVisible) {
        String sql = "update student set isVisible = ? where id=? ";
        int i = 0;
        try {
            i = qr.update(sql, new Object[]{isVisible, id});
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return i;
    }
}
